﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using CinemaBookingUI.WCFReference;

namespace CinemaBookingUI
{
    public partial class TicketInfo : Form
    {
        private WCFReference.IWcfCinemaService wcf = SingletonWCF.Instance.WCFNetTcp();
        private Booking booked;

        public TicketInfo(Booking book)
        {
            booked = book;
            InitializeComponent();

            Customer cust = wcf.ReadCustomer(booked.CustomerPhone).First();

            lblPhone.Text = cust.PhoneNo;
            if (cust.Name != null || cust.Name != "")
            {
                lblName.Text = cust.Name;
            }
            if (cust.Email != null || cust.Email != "")
            {
                lblEmail.Text = cust.Email;
            }
            lblTotalPrice.Text = booked.TotalPrice.ToString();

            dgvTickets.DataSource = wcf.ReadTicket(booked);

        }

        private void btnDiscount_Click(object sender, EventArgs e)
        {
            MessageBox.Show("Tilføj rabat\r\n(Der er pt ingen mulighed for at tilføje rabat)");
        }

        private void btnBuy_Click(object sender, EventArgs e)
        {

            booked.Status = 1;
            wcf.UpdateBooking(booked);

            #region MessageBox
            string message = "Bookingen er nu solgt.\r\nKlik på ok for at gå til start skærmen.";
            string caption = "Resultat";
            MessageBoxButtons but = MessageBoxButtons.OK;
            DialogResult result;

            result = MessageBox.Show(message, caption, but);

            if (result == System.Windows.Forms.DialogResult.OK)
            {
                this.Close();
                
            }
            #endregion
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}